package com.google.android.exoplayer2.extractor.mp4;

import android.util.Pair;
import android.util.SparseArray;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.ActivityChooserView.ActivityChooserViewAdapter;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
import com.google.android.exoplayer2.extractor.Extractor;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import o.adt;
import o.adv;
import o.adw;
import o.ady;
import o.adz;
import o.aea;
import o.aef;
import o.aeu;
import o.aeu.e;
import o.aez;
import o.afb;
import o.afc;
import o.afe;
import o.aff;
import o.afg;
import o.afh;
import o.ajv;
import o.amm;
import o.amz;
import o.anc;
import o.and;
import o.anq;
import o.anr;

public final class FragmentedMp4Extractor implements Extractor {
    private static final byte[] ˊ = new byte[]{(byte) -94, (byte) 57, (byte) 79, (byte) 82, (byte) 90, (byte) -101, (byte) 79, (byte) 20, (byte) -94, (byte) 68, (byte) 108, (byte) 66, (byte) 124, (byte) 100, (byte) -115, (byte) -12};
    public static final adw ˋ = afc.ˊ;
    private static final Format ˏ = Format.ˏ(null, "application/x-emsg", Long.MAX_VALUE);
    private static final int ॱ = anr.ᐝ("seig");
    @Nullable
    private final DrmInitData ʻ;
    private final ArrayDeque<e> ʻॱ;
    private final SparseArray<d> ʼ;
    private anc ʼॱ;
    private final anc ʽ;
    private int ʽॱ;
    private long ʾ;
    private int ʿ;
    private long ˈ;
    private long ˉ;
    private long ˊˊ;
    private int ˊˋ;
    @Nullable
    private final anq ˊॱ;
    private d ˊᐝ;
    private long ˋˊ;
    private boolean ˋˋ;
    private final anc ˋॱ;
    private ady ˋᐝ;
    private int ˌ;
    private int ˍ;
    private final int ˎ;
    private aef[] ˎˎ;
    private boolean ˎˏ;
    private final anc ˏॱ;
    private final byte[] ͺ;
    private aef[] ͺॱ;
    private final anc ॱˊ;
    private int ॱˋ;
    private final ArrayDeque<b> ॱˎ;
    @Nullable
    private final Track ॱॱ;
    @Nullable
    private final aef ॱᐝ;
    private final List<Format> ᐝ;
    private int ᐝॱ;

    static final class b {
        public final int ˊ;
        public final long ˏ;

        public b(long j, int i) {
            this.ˏ = j;
            this.ˊ = i;
        }
    }

    static final class d {
        public int ʻ;
        private final anc ʼ = new anc(1);
        public int ʽ;
        public int ˊ;
        public final afh ˋ = new afh();
        public Track ˎ;
        public final aef ˏ;
        public afb ॱ;
        public int ॱॱ;
        private final anc ᐝ = new anc();

        public d(aef o_aef) {
            this.ˏ = o_aef;
        }

        public void ॱ(Track track, afb o_afb) {
            this.ˎ = (Track) amm.ॱ(track);
            this.ॱ = (afb) amm.ॱ(o_afb);
            this.ˏ.ˎ(track.ॱॱ);
            ˋ();
        }

        public void ˏ(DrmInitData drmInitData) {
            afe ˋ = this.ˎ.ˋ(this.ˋ.ˊ.ॱ);
            this.ˏ.ˎ(this.ˎ.ॱॱ.ˋ(drmInitData.ˊ(ˋ != null ? ˋ.ˎ : null)));
        }

        public void ˋ() {
            this.ˋ.ˋ();
            this.ˊ = 0;
            this.ʻ = 0;
            this.ʽ = 0;
            this.ॱॱ = 0;
        }

        public void ˎ(long j) {
            long ˋ = C.ˋ(j);
            int i = this.ˊ;
            while (i < this.ˋ.ॱॱ && this.ˋ.ॱ(i) < ˋ) {
                if (this.ˋ.ॱˊ[i]) {
                    this.ॱॱ = i;
                }
                i++;
            }
        }

        public boolean ॱ() {
            this.ˊ++;
            this.ʽ++;
            if (this.ʽ != this.ˋ.ʽ[this.ʻ]) {
                return true;
            }
            this.ʻ++;
            this.ʽ = 0;
            return false;
        }

        public int ˏ() {
            afe ˎ = ˎ();
            if (ˎ == null) {
                return 0;
            }
            anc o_anc;
            int i;
            int i2;
            if (ˎ.ॱ != 0) {
                o_anc = this.ˋ.ॱˋ;
                i = ˎ.ॱ;
            } else {
                byte[] bArr = ˎ.ˋ;
                this.ᐝ.ॱ(bArr, bArr.length);
                o_anc = this.ᐝ;
                i = bArr.length;
            }
            boolean ˊ = this.ˋ.ˊ(this.ˊ);
            byte[] bArr2 = this.ʼ.ˏ;
            if (ˊ) {
                i2 = DnsConfig.MAX_CACHE_ENTRIES;
            } else {
                i2 = 0;
            }
            bArr2[0] = (byte) (i2 | i);
            this.ʼ.ˋ(0);
            this.ˏ.ˎ(this.ʼ, 1);
            this.ˏ.ˎ(o_anc, i);
            if (!ˊ) {
                return i + 1;
            }
            o_anc = this.ˋ.ॱˋ;
            i2 = o_anc.ॱॱ();
            o_anc.ˎ(-2);
            i2 = (i2 * 6) + 2;
            this.ˏ.ˎ(o_anc, i2);
            return (i + 1) + i2;
        }

        private void ˊ() {
            afe ˎ = ˎ();
            if (ˎ != null) {
                anc o_anc = this.ˋ.ॱˋ;
                if (ˎ.ॱ != 0) {
                    o_anc.ˎ(ˎ.ॱ);
                }
                if (this.ˋ.ˊ(this.ˊ)) {
                    o_anc.ˎ(o_anc.ॱॱ() * 6);
                }
            }
        }

        private afe ˎ() {
            afe o_afe;
            int i = this.ˋ.ˊ.ॱ;
            if (this.ˋ.ˊॱ != null) {
                o_afe = this.ˋ.ˊॱ;
            } else {
                o_afe = this.ˎ.ˋ(i);
            }
            return (o_afe == null || !o_afe.ˊ) ? null : o_afe;
        }
    }

    public FragmentedMp4Extractor() {
        this(0);
    }

    public FragmentedMp4Extractor(int i) {
        this(i, null);
    }

    public FragmentedMp4Extractor(int i, @Nullable anq o_anq) {
        this(i, o_anq, null, null);
    }

    public FragmentedMp4Extractor(int i, @Nullable anq o_anq, @Nullable Track track, @Nullable DrmInitData drmInitData) {
        this(i, o_anq, track, drmInitData, Collections.emptyList());
    }

    public FragmentedMp4Extractor(int i, @Nullable anq o_anq, @Nullable Track track, @Nullable DrmInitData drmInitData, List<Format> list) {
        this(i, o_anq, track, drmInitData, list, null);
    }

    public FragmentedMp4Extractor(int i, @Nullable anq o_anq, @Nullable Track track, @Nullable DrmInitData drmInitData, List<Format> list, @Nullable aef o_aef) {
        this.ˎ = (track != null ? 8 : 0) | i;
        this.ˊॱ = o_anq;
        this.ॱॱ = track;
        this.ʻ = drmInitData;
        this.ᐝ = Collections.unmodifiableList(list);
        this.ॱᐝ = o_aef;
        this.ˏॱ = new anc(16);
        this.ʽ = new anc(and.ˏ);
        this.ॱˊ = new anc(5);
        this.ˋॱ = new anc();
        this.ͺ = new byte[16];
        this.ʻॱ = new ArrayDeque();
        this.ॱˎ = new ArrayDeque();
        this.ʼ = new SparseArray();
        this.ˋˊ = -9223372036854775807L;
        this.ˉ = -9223372036854775807L;
        this.ˊˊ = -9223372036854775807L;
        ˋ();
    }

    public boolean ˎ(adv o_adv) throws IOException, InterruptedException {
        return afg.ॱ(o_adv);
    }

    public void ˏ(ady o_ady) {
        this.ˋᐝ = o_ady;
        if (this.ॱॱ != null) {
            d dVar = new d(o_ady.ˊ(0, this.ॱॱ.ˋ));
            dVar.ॱ(this.ॱॱ, new afb(0, 0, 0, 0));
            this.ʼ.put(0, dVar);
            ˎ();
            this.ˋᐝ.ˊ();
        }
    }

    public void ˊ(long j, long j2) {
        int size = this.ʼ.size();
        for (int i = 0; i < size; i++) {
            ((d) this.ʼ.valueAt(i)).ˋ();
        }
        this.ॱˎ.clear();
        this.ʿ = 0;
        this.ˉ = j2;
        this.ʻॱ.clear();
        ˋ();
    }

    public void ॱ() {
    }

    public int ˎ(adv o_adv, adz o_adz) throws IOException, InterruptedException {
        while (true) {
            switch (this.ॱˋ) {
                case 0:
                    if (ॱ(o_adv)) {
                        break;
                    }
                    return -1;
                case 1:
                    ˏ(o_adv);
                    break;
                case 2:
                    ˊ(o_adv);
                    break;
                default:
                    if (!ˋ(o_adv)) {
                        break;
                    }
                    return 0;
            }
        }
    }

    private void ˋ() {
        this.ॱˋ = 0;
        this.ʽॱ = 0;
    }

    private boolean ॱ(adv o_adv) throws IOException, InterruptedException {
        long ॱ;
        if (this.ʽॱ == 0) {
            if (!o_adv.ˊ(this.ˏॱ.ˏ, 0, 8, true)) {
                return false;
            }
            this.ʽॱ = 8;
            this.ˏॱ.ˋ(0);
            this.ˈ = this.ˏॱ.ˋॱ();
            this.ᐝॱ = this.ˏॱ.ॱᐝ();
        }
        if (this.ˈ == 1) {
            o_adv.ˏ(this.ˏॱ.ˏ, 8, 8);
            this.ʽॱ += 8;
            this.ˈ = this.ˏॱ.ʼॱ();
        } else if (this.ˈ == 0) {
            ॱ = o_adv.ॱ();
            if (ॱ == -1 && !this.ʻॱ.isEmpty()) {
                ॱ = ((e) this.ʻॱ.peek()).ॱᐧ;
            }
            if (ॱ != -1) {
                this.ˈ = (ॱ - o_adv.ˊ()) + ((long) this.ʽॱ);
            }
        }
        if (this.ˈ < ((long) this.ʽॱ)) {
            throw new ParserException("Atom size less than header length (unsupported).");
        }
        ॱ = o_adv.ˊ() - ((long) this.ʽॱ);
        if (this.ᐝॱ == aeu.ˎˏ) {
            int size = this.ʼ.size();
            for (int i = 0; i < size; i++) {
                afh o_afh = ((d) this.ʼ.valueAt(i)).ˋ;
                o_afh.ˎ = ॱ;
                o_afh.ˏ = ॱ;
                o_afh.ॱ = ॱ;
            }
        }
        if (this.ᐝॱ == aeu.ॱॱ) {
            this.ˊᐝ = null;
            this.ʾ = this.ˈ + ॱ;
            if (!this.ˎˏ) {
                this.ˋᐝ.ˎ(new aea.e(this.ˋˊ, ॱ));
                this.ˎˏ = true;
            }
            this.ॱˋ = 2;
            return true;
        }
        if (ˊ(this.ᐝॱ)) {
            long ˊ = (o_adv.ˊ() + this.ˈ) - 8;
            this.ʻॱ.push(new e(this.ᐝॱ, ˊ));
            if (this.ˈ == ((long) this.ʽॱ)) {
                ˏ(ˊ);
            } else {
                ˋ();
            }
        } else if (ˋ(this.ᐝॱ)) {
            if (this.ʽॱ != 8) {
                throw new ParserException("Leaf atom defines extended atom size (unsupported).");
            } else if (this.ˈ > 2147483647L) {
                throw new ParserException("Leaf atom with length > 2147483647 (unsupported).");
            } else {
                this.ʼॱ = new anc((int) this.ˈ);
                System.arraycopy(this.ˏॱ.ˏ, 0, this.ʼॱ.ˏ, 0, 8);
                this.ॱˋ = 1;
            }
        } else if (this.ˈ > 2147483647L) {
            throw new ParserException("Skipping atom with length > 2147483647 (unsupported).");
        } else {
            this.ʼॱ = null;
            this.ॱˋ = 1;
        }
        return true;
    }

    private void ˏ(adv o_adv) throws IOException, InterruptedException {
        int i = ((int) this.ˈ) - this.ʽॱ;
        if (this.ʼॱ != null) {
            o_adv.ˏ(this.ʼॱ.ˏ, 8, i);
            ˋ(new o.aeu.d(this.ᐝॱ, this.ʼॱ), o_adv.ˊ());
        } else {
            o_adv.ॱ(i);
        }
        ˏ(o_adv.ˊ());
    }

    private void ˏ(long j) throws ParserException {
        while (!this.ʻॱ.isEmpty() && ((e) this.ʻॱ.peek()).ॱᐧ == j) {
            ˎ((e) this.ʻॱ.pop());
        }
        ˋ();
    }

    private void ˋ(o.aeu.d dVar, long j) throws ParserException {
        if (!this.ʻॱ.isEmpty()) {
            ((e) this.ʻॱ.peek()).ॱ(dVar);
        } else if (dVar.ॱꓸ == aeu.ˊᐝ) {
            Pair ˊ = ˊ(dVar.ॱᐨ, j);
            this.ˊˊ = ((Long) ˊ.first).longValue();
            this.ˋᐝ.ˎ((aea) ˊ.second);
            this.ˎˏ = true;
        } else if (dVar.ॱꓸ == aeu.ٴ) {
            ˋ(dVar.ॱᐨ);
        }
    }

    private void ˎ(e eVar) throws ParserException {
        if (eVar.ॱꓸ == aeu.ˊˊ) {
            ˋ(eVar);
        } else if (eVar.ॱꓸ == aeu.ˎˏ) {
            ˏ(eVar);
        } else if (!this.ʻॱ.isEmpty()) {
            ((e) this.ʻॱ.peek()).ˏ(eVar);
        }
    }

    private void ˋ(e eVar) throws ParserException {
        DrmInitData drmInitData;
        boolean z = true;
        int i = 0;
        amm.ˏ(this.ॱॱ == null, "Unexpected moov box.");
        if (this.ʻ != null) {
            drmInitData = this.ʻ;
        } else {
            drmInitData = ˋ(eVar.ॱᶥ);
        }
        e ˋ = eVar.ˋ(aeu.ˏˎ);
        SparseArray sparseArray = new SparseArray();
        long j = -9223372036854775807L;
        int size = ˋ.ॱᶥ.size();
        for (int i2 = 0; i2 < size; i2++) {
            o.aeu.d dVar = (o.aeu.d) ˋ.ॱᶥ.get(i2);
            if (dVar.ॱꓸ == aeu.ˈ) {
                Pair ॱ = ॱ(dVar.ॱᐨ);
                sparseArray.put(((Integer) ॱ.first).intValue(), ॱ.second);
            } else if (dVar.ॱꓸ == aeu.ͺॱ) {
                j = ˏ(dVar.ॱᐨ);
            }
        }
        SparseArray sparseArray2 = new SparseArray();
        int size2 = eVar.ॱᐨ.size();
        for (size = 0; size < size2; size++) {
            Track ॱ2;
            e eVar2 = (e) eVar.ॱᐨ.get(size);
            if (eVar2.ॱꓸ == aeu.ˊˋ) {
                boolean z2;
                o.aeu.d ˊ = eVar.ˊ(aeu.ˉ);
                if ((this.ˎ & 16) != 0) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                ॱ2 = aez.ॱ(eVar2, ˊ, j, drmInitData, z2, false);
                if (ॱ2 != null) {
                    sparseArray2.put(ॱ2.ˊ, ॱ2);
                }
            }
        }
        int size3 = sparseArray2.size();
        if (this.ʼ.size() == 0) {
            while (i < size3) {
                ॱ2 = (Track) sparseArray2.valueAt(i);
                d dVar2 = new d(this.ˋᐝ.ˊ(i, ॱ2.ˋ));
                dVar2.ॱ(ॱ2, ˏ(sparseArray, ॱ2.ˊ));
                this.ʼ.put(ॱ2.ˊ, dVar2);
                this.ˋˊ = Math.max(this.ˋˊ, ॱ2.ˎ);
                i++;
            }
            ˎ();
            this.ˋᐝ.ˊ();
            return;
        }
        if (this.ʼ.size() != size3) {
            z = false;
        }
        amm.ˏ(z);
        while (i < size3) {
            ॱ2 = (Track) sparseArray2.valueAt(i);
            ((d) this.ʼ.get(ॱ2.ˊ)).ॱ(ॱ2, ˏ(sparseArray, ॱ2.ˊ));
            i++;
        }
    }

    private afb ˏ(SparseArray<afb> sparseArray, int i) {
        if (sparseArray.size() == 1) {
            return (afb) sparseArray.valueAt(0);
        }
        return (afb) amm.ॱ(sparseArray.get(i));
    }

    private void ˏ(e eVar) throws ParserException {
        DrmInitData drmInitData;
        int i;
        int i2 = 0;
        ॱ(eVar, this.ʼ, this.ˎ, this.ͺ);
        if (this.ʻ != null) {
            drmInitData = null;
        } else {
            drmInitData = ˋ(eVar.ॱᶥ);
        }
        if (drmInitData != null) {
            int size = this.ʼ.size();
            for (i = 0; i < size; i++) {
                ((d) this.ʼ.valueAt(i)).ˏ(drmInitData);
            }
        }
        if (this.ˉ != -9223372036854775807L) {
            i = this.ʼ.size();
            while (i2 < i) {
                ((d) this.ʼ.valueAt(i2)).ˎ(this.ˉ);
                i2++;
            }
            this.ˉ = -9223372036854775807L;
        }
    }

    private void ˎ() {
        int i = 0;
        if (this.ˎˎ == null) {
            int i2;
            this.ˎˎ = new aef[2];
            if (this.ॱᐝ != null) {
                i2 = 1;
                this.ˎˎ[0] = this.ॱᐝ;
            } else {
                i2 = 0;
            }
            if ((this.ˎ & 4) != 0) {
                int i3 = i2 + 1;
                this.ˎˎ[i2] = this.ˋᐝ.ˊ(this.ʼ.size(), 4);
                i2 = i3;
            }
            this.ˎˎ = (aef[]) Arrays.copyOf(this.ˎˎ, i2);
            for (aef ˎ : this.ˎˎ) {
                ˎ.ˎ(ˏ);
            }
        }
        if (this.ͺॱ == null) {
            this.ͺॱ = new aef[this.ᐝ.size()];
            while (i < this.ͺॱ.length) {
                aef ˊ = this.ˋᐝ.ˊ((this.ʼ.size() + 1) + i, 3);
                ˊ.ˎ((Format) this.ᐝ.get(i));
                this.ͺॱ[i] = ˊ;
                i++;
            }
        }
    }

    private void ˋ(anc o_anc) {
        if (this.ˎˎ != null && this.ˎˎ.length != 0) {
            o_anc.ˋ(12);
            int ˊ = o_anc.ˊ();
            o_anc.ˉ();
            o_anc.ˉ();
            long ॱ = anr.ॱ(o_anc.ˋॱ(), 1000000, o_anc.ˋॱ());
            int ˋ = o_anc.ˋ();
            o_anc.ˏ[ˋ - 4] = (byte) 0;
            o_anc.ˏ[ˋ - 3] = (byte) 0;
            o_anc.ˏ[ˋ - 2] = (byte) 0;
            o_anc.ˏ[ˋ - 1] = (byte) 0;
            for (aef o_aef : this.ˎˎ) {
                o_anc.ˋ(12);
                o_aef.ˎ(o_anc, ˊ);
            }
            if (this.ˊˊ != -9223372036854775807L) {
                ॱ += this.ˊˊ;
                if (this.ˊॱ != null) {
                    ॱ = this.ˊॱ.ˊ(ॱ);
                }
                for (aef ˋ2 : this.ˎˎ) {
                    ˋ2.ˋ(ॱ, 1, ˊ, 0, null);
                }
                return;
            }
            this.ॱˎ.addLast(new b(ॱ, ˊ));
            this.ʿ += ˊ;
        }
    }

    private static Pair<Integer, afb> ॱ(anc o_anc) {
        o_anc.ˋ(12);
        return Pair.create(Integer.valueOf(o_anc.ॱᐝ()), new afb(o_anc.ʽॱ() - 1, o_anc.ʽॱ(), o_anc.ʽॱ(), o_anc.ॱᐝ()));
    }

    private static long ˏ(anc o_anc) {
        o_anc.ˋ(8);
        return aeu.ॱ(o_anc.ॱᐝ()) == 0 ? o_anc.ˋॱ() : o_anc.ʼॱ();
    }

    private static void ॱ(e eVar, SparseArray<d> sparseArray, int i, byte[] bArr) throws ParserException {
        int size = eVar.ॱᐨ.size();
        for (int i2 = 0; i2 < size; i2++) {
            e eVar2 = (e) eVar.ॱᐨ.get(i2);
            if (eVar2.ॱꓸ == aeu.ˑ) {
                ˊ(eVar2, sparseArray, i, bArr);
            }
        }
    }

    private static void ˊ(e eVar, SparseArray<d> sparseArray, int i, byte[] bArr) throws ParserException {
        d ˏ = ˏ(eVar.ˊ(aeu.ʼॱ).ॱᐨ, (SparseArray) sparseArray);
        if (ˏ != null) {
            afh o_afh = ˏ.ˋ;
            long j = o_afh.ॱᐝ;
            ˏ.ˋ();
            if (eVar.ˊ(aeu.ʾ) != null && (i & 2) == 0) {
                j = ˊ(eVar.ˊ(aeu.ʾ).ॱᐨ);
            }
            ॱ(eVar, ˏ, j, i);
            afe ˋ = ˏ.ˎ.ˋ(o_afh.ˊ.ॱ);
            o.aeu.d ˊ = eVar.ˊ(aeu.ᶥ);
            if (ˊ != null) {
                ˊ(ˋ, ˊ.ॱᐨ, o_afh);
            }
            ˊ = eVar.ˊ(aeu.ﾞ);
            if (ˊ != null) {
                ॱ(ˊ.ॱᐨ, o_afh);
            }
            ˊ = eVar.ˊ(aeu.ﹳ);
            if (ˊ != null) {
                ˎ(ˊ.ॱᐨ, o_afh);
            }
            ˊ = eVar.ˊ(aeu.ʹ);
            o.aeu.d ˊ2 = eVar.ˊ(aeu.ﾟ);
            if (!(ˊ == null || ˊ2 == null)) {
                ˏ(ˊ.ॱᐨ, ˊ2.ॱᐨ, ˋ != null ? ˋ.ˎ : null, o_afh);
            }
            int size = eVar.ॱᶥ.size();
            for (int i2 = 0; i2 < size; i2++) {
                o.aeu.d dVar = (o.aeu.d) eVar.ॱᶥ.get(i2);
                if (dVar.ॱꓸ == aeu.ꞌ) {
                    ॱ(dVar.ॱᐨ, o_afh, bArr);
                }
            }
        }
    }

    private static void ॱ(e eVar, d dVar, long j, int i) {
        List list = eVar.ॱᶥ;
        int size = list.size();
        int i2 = 0;
        int i3 = 0;
        int i4 = 0;
        while (i2 < size) {
            int ʽॱ;
            o.aeu.d dVar2 = (o.aeu.d) list.get(i2);
            if (dVar2.ॱꓸ == aeu.ˋˊ) {
                anc o_anc = dVar2.ॱᐨ;
                o_anc.ˋ(12);
                ʽॱ = o_anc.ʽॱ();
                if (ʽॱ > 0) {
                    ʽॱ += i3;
                    i3 = i4 + 1;
                    i2++;
                    i4 = i3;
                    i3 = ʽॱ;
                }
            }
            ʽॱ = i3;
            i3 = i4;
            i2++;
            i4 = i3;
            i3 = ʽॱ;
        }
        dVar.ʻ = 0;
        dVar.ʽ = 0;
        dVar.ˊ = 0;
        dVar.ˋ.ॱ(i4, i3);
        int i5 = 0;
        i3 = 0;
        for (int i6 = 0; i6 < size; i6++) {
            dVar2 = (o.aeu.d) list.get(i6);
            if (dVar2.ॱꓸ == aeu.ˋˊ) {
                int i7 = i3 + 1;
                i5 = ॱ(dVar, i3, j, i, dVar2.ॱᐨ, i5);
                i3 = i7;
            }
        }
    }

    private static void ˊ(afe o_afe, anc o_anc, afh o_afh) throws ParserException {
        boolean z = true;
        int i = o_afe.ॱ;
        o_anc.ˋ(8);
        if ((aeu.ˎ(o_anc.ॱᐝ()) & 1) == 1) {
            o_anc.ˎ(8);
        }
        int ʽ = o_anc.ʽ();
        int ʽॱ = o_anc.ʽॱ();
        if (ʽॱ != o_afh.ॱॱ) {
            throw new ParserException("Length mismatch: " + ʽॱ + ", " + o_afh.ॱॱ);
        }
        if (ʽ == 0) {
            boolean[] zArr = o_afh.ˋॱ;
            int i2 = 0;
            ʽ = 0;
            while (i2 < ʽॱ) {
                boolean z2;
                int ʽ2 = o_anc.ʽ();
                int i3 = ʽ + ʽ2;
                if (ʽ2 > i) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                zArr[i2] = z2;
                i2++;
                ʽ = i3;
            }
        } else {
            if (ʽ <= i) {
                z = false;
            }
            ʽ = (ʽ * ʽॱ) + 0;
            Arrays.fill(o_afh.ˋॱ, 0, ʽॱ, z);
        }
        o_afh.ˏ(ʽ);
    }

    private static void ॱ(anc o_anc, afh o_afh) throws ParserException {
        o_anc.ˋ(8);
        int ॱᐝ = o_anc.ॱᐝ();
        if ((aeu.ˎ(ॱᐝ) & 1) == 1) {
            o_anc.ˎ(8);
        }
        int ʽॱ = o_anc.ʽॱ();
        if (ʽॱ != 1) {
            throw new ParserException("Unexpected saio entry count: " + ʽॱ);
        }
        ॱᐝ = aeu.ॱ(ॱᐝ);
        o_afh.ˏ = (ॱᐝ == 0 ? o_anc.ˋॱ() : o_anc.ʼॱ()) + o_afh.ˏ;
    }

    private static d ˏ(anc o_anc, SparseArray<d> sparseArray) {
        o_anc.ˋ(8);
        int ˎ = aeu.ˎ(o_anc.ॱᐝ());
        d ॱ = ॱ((SparseArray) sparseArray, o_anc.ॱᐝ());
        if (ॱ == null) {
            return null;
        }
        if ((ˎ & 1) != 0) {
            long ʼॱ = o_anc.ʼॱ();
            ॱ.ˋ.ॱ = ʼॱ;
            ॱ.ˋ.ˏ = ʼॱ;
        }
        afb o_afb = ॱ.ॱ;
        ॱ.ˋ.ˊ = new afb((ˎ & 2) != 0 ? o_anc.ʽॱ() - 1 : o_afb.ॱ, (ˎ & 8) != 0 ? o_anc.ʽॱ() : o_afb.ˏ, (ˎ & 16) != 0 ? o_anc.ʽॱ() : o_afb.ˋ, (ˎ & 32) != 0 ? o_anc.ʽॱ() : o_afb.ˎ);
        return ॱ;
    }

    @Nullable
    private static d ॱ(SparseArray<d> sparseArray, int i) {
        if (sparseArray.size() == 1) {
            return (d) sparseArray.valueAt(0);
        }
        return (d) sparseArray.get(i);
    }

    private static long ˊ(anc o_anc) {
        o_anc.ˋ(8);
        return aeu.ॱ(o_anc.ॱᐝ()) == 1 ? o_anc.ʼॱ() : o_anc.ˋॱ();
    }

    private static int ॱ(d dVar, int i, long j, int i2, anc o_anc, int i3) {
        Object obj;
        long ॱ;
        o_anc.ˋ(8);
        int ˎ = aeu.ˎ(o_anc.ॱᐝ());
        Track track = dVar.ˎ;
        afh o_afh = dVar.ˋ;
        afb o_afb = o_afh.ˊ;
        o_afh.ʽ[i] = o_anc.ʽॱ();
        o_afh.ʻ[i] = o_afh.ॱ;
        if ((ˎ & 1) != 0) {
            long[] jArr = o_afh.ʻ;
            jArr[i] = jArr[i] + ((long) o_anc.ॱᐝ());
        }
        Object obj2 = (ˎ & 4) != 0 ? 1 : null;
        int i4 = o_afb.ˎ;
        if (obj2 != null) {
            i4 = o_anc.ʽॱ();
        }
        Object obj3 = (ˎ & 256) != 0 ? 1 : null;
        Object obj4 = (ˎ & WXMediaMessage.TITLE_LENGTH_LIMIT) != 0 ? 1 : null;
        Object obj5 = (ˎ & WXMediaMessage.DESCRIPTION_LENGTH_LIMIT) != 0 ? 1 : null;
        if ((ˎ & 2048) != 0) {
            obj = 1;
        } else {
            obj = null;
        }
        if (track.ᐝ != null && track.ᐝ.length == 1 && track.ᐝ[0] == 0) {
            ॱ = anr.ॱ(track.ʽ[0], 1000, track.ॱ);
        } else {
            ॱ = 0;
        }
        int[] iArr = o_afh.ᐝ;
        int[] iArr2 = o_afh.ʼ;
        long[] jArr2 = o_afh.ͺ;
        boolean[] zArr = o_afh.ॱˊ;
        Object obj6 = (track.ˋ != 2 || (i2 & 1) == 0) ? null : 1;
        int i5 = i3 + o_afh.ʽ[i];
        long j2 = track.ॱ;
        if (i > 0) {
            j = o_afh.ॱᐝ;
        }
        long j3 = j;
        while (i3 < i5) {
            int ʽॱ = obj3 != null ? o_anc.ʽॱ() : o_afb.ˏ;
            int ʽॱ2 = obj4 != null ? o_anc.ʽॱ() : o_afb.ˋ;
            int ॱᐝ = (i3 != 0 || obj2 == null) ? obj5 != null ? o_anc.ॱᐝ() : o_afb.ˎ : i4;
            if (obj != null) {
                iArr2[i3] = (int) ((((long) o_anc.ॱᐝ()) * 1000) / j2);
            } else {
                iArr2[i3] = 0;
            }
            jArr2[i3] = anr.ॱ(j3, 1000, j2) - ॱ;
            iArr[i3] = ʽॱ2;
            boolean z = ((ॱᐝ >> 16) & 1) == 0 && (obj6 == null || i3 == 0);
            zArr[i3] = z;
            j3 += (long) ʽॱ;
            i3++;
        }
        o_afh.ॱᐝ = j3;
        return i5;
    }

    private static void ॱ(anc o_anc, afh o_afh, byte[] bArr) throws ParserException {
        o_anc.ˋ(8);
        o_anc.ˎ(bArr, 0, 16);
        if (Arrays.equals(bArr, ˊ)) {
            ˏ(o_anc, 16, o_afh);
        }
    }

    private static void ˎ(anc o_anc, afh o_afh) throws ParserException {
        ˏ(o_anc, 0, o_afh);
    }

    private static void ˏ(anc o_anc, int i, afh o_afh) throws ParserException {
        o_anc.ˋ(i + 8);
        int ˎ = aeu.ˎ(o_anc.ॱᐝ());
        if ((ˎ & 1) != 0) {
            throw new ParserException("Overriding TrackEncryptionBox parameters is unsupported.");
        }
        boolean z;
        if ((ˎ & 2) != 0) {
            z = true;
        } else {
            z = false;
        }
        int ʽॱ = o_anc.ʽॱ();
        if (ʽॱ != o_afh.ॱॱ) {
            throw new ParserException("Length mismatch: " + ʽॱ + ", " + o_afh.ॱॱ);
        }
        Arrays.fill(o_afh.ˋॱ, 0, ʽॱ, z);
        o_afh.ˏ(o_anc.ˊ());
        o_afh.ॱ(o_anc);
    }

    private static void ˏ(anc o_anc, anc o_anc2, String str, afh o_afh) throws ParserException {
        o_anc.ˋ(8);
        int ॱᐝ = o_anc.ॱᐝ();
        if (o_anc.ॱᐝ() == ॱ) {
            if (aeu.ॱ(ॱᐝ) == 1) {
                o_anc.ˎ(4);
            }
            if (o_anc.ॱᐝ() != 1) {
                throw new ParserException("Entry count in sbgp != 1 (unsupported).");
            }
            o_anc2.ˋ(8);
            ॱᐝ = o_anc2.ॱᐝ();
            if (o_anc2.ॱᐝ() == ॱ) {
                ॱᐝ = aeu.ॱ(ॱᐝ);
                if (ॱᐝ == 1) {
                    if (o_anc2.ˋॱ() == 0) {
                        throw new ParserException("Variable length description in sgpd found (unsupported)");
                    }
                } else if (ॱᐝ >= 2) {
                    o_anc2.ˎ(4);
                }
                if (o_anc2.ˋॱ() != 1) {
                    throw new ParserException("Entry count in sgpd != 1 (unsupported).");
                }
                o_anc2.ˎ(1);
                ॱᐝ = o_anc2.ʽ();
                int i = (ॱᐝ & 240) >> 4;
                int i2 = ॱᐝ & 15;
                boolean z = o_anc2.ʽ() == 1;
                if (z) {
                    int ʽ = o_anc2.ʽ();
                    byte[] bArr = new byte[16];
                    o_anc2.ˎ(bArr, 0, bArr.length);
                    byte[] bArr2 = null;
                    if (z && ʽ == 0) {
                        int ʽ2 = o_anc2.ʽ();
                        bArr2 = new byte[ʽ2];
                        o_anc2.ˎ(bArr2, 0, ʽ2);
                    }
                    o_afh.ˏॱ = true;
                    o_afh.ˊॱ = new afe(z, str, ʽ, bArr, i, i2, bArr2);
                }
            }
        }
    }

    private static Pair<Long, adt> ˊ(anc o_anc, long j) throws ParserException {
        long ˋॱ;
        long ˋॱ2;
        o_anc.ˋ(8);
        int ॱ = aeu.ॱ(o_anc.ॱᐝ());
        o_anc.ˎ(4);
        long ˋॱ3 = o_anc.ˋॱ();
        if (ॱ == 0) {
            ˋॱ = o_anc.ˋॱ() + j;
            ˋॱ2 = o_anc.ˋॱ();
        } else {
            ˋॱ = o_anc.ʼॱ() + j;
            ˋॱ2 = o_anc.ʼॱ();
        }
        long ॱ2 = anr.ॱ(ˋॱ2, 1000000, ˋॱ3);
        o_anc.ˎ(2);
        int ॱॱ = o_anc.ॱॱ();
        int[] iArr = new int[ॱॱ];
        long[] jArr = new long[ॱॱ];
        long[] jArr2 = new long[ॱॱ];
        long[] jArr3 = new long[ॱॱ];
        long j2 = ˋॱ;
        int i = 0;
        long j3 = ˋॱ2;
        ˋॱ2 = ॱ2;
        while (i < ॱॱ) {
            int ॱᐝ = o_anc.ॱᐝ();
            if ((Integer.MIN_VALUE & ॱᐝ) != 0) {
                throw new ParserException("Unhandled indirect reference");
            }
            long ˋॱ4 = o_anc.ˋॱ();
            iArr[i] = ॱᐝ & ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED;
            jArr[i] = j2;
            jArr3[i] = ˋॱ2;
            ˋॱ2 = j3 + ˋॱ4;
            ˋॱ4 = anr.ॱ(ˋॱ2, 1000000, ˋॱ3);
            jArr2[i] = ˋॱ4 - jArr3[i];
            o_anc.ˎ(4);
            j2 += (long) iArr[i];
            i++;
            j3 = ˋॱ2;
            ˋॱ2 = ˋॱ4;
        }
        return Pair.create(Long.valueOf(ॱ2), new adt(iArr, jArr, jArr2, jArr3));
    }

    private void ˊ(adv o_adv) throws IOException, InterruptedException {
        d dVar = null;
        long j = Long.MAX_VALUE;
        int size = this.ʼ.size();
        int i = 0;
        while (i < size) {
            d dVar2;
            long j2;
            afh o_afh = ((d) this.ʼ.valueAt(i)).ˋ;
            long j3;
            if (!o_afh.ʻॱ || o_afh.ˏ >= j) {
                j3 = j;
                dVar2 = dVar;
                j2 = j3;
            } else {
                j3 = o_afh.ˏ;
                dVar2 = (d) this.ʼ.valueAt(i);
                j2 = j3;
            }
            i++;
            dVar = dVar2;
            j = j2;
        }
        if (dVar == null) {
            this.ॱˋ = 3;
            return;
        }
        int ˊ = (int) (j - o_adv.ˊ());
        if (ˊ < 0) {
            throw new ParserException("Offset to encryption data was negative.");
        }
        o_adv.ॱ(ˊ);
        dVar.ˋ.ॱ(o_adv);
    }

    private boolean ˋ(adv o_adv) throws IOException, InterruptedException {
        int ˊ;
        int i;
        if (this.ॱˋ == 3) {
            if (this.ˊᐝ == null) {
                d ॱ = ॱ(this.ʼ);
                if (ॱ == null) {
                    ˊ = (int) (this.ʾ - o_adv.ˊ());
                    if (ˊ < 0) {
                        throw new ParserException("Offset to end of mdat was negative.");
                    }
                    o_adv.ॱ(ˊ);
                    ˋ();
                    return false;
                }
                ˊ = (int) (ॱ.ˋ.ʻ[ॱ.ʻ] - o_adv.ˊ());
                if (ˊ < 0) {
                    amz.ˏ("FragmentedMp4Extractor", "Ignoring negative offset to sample data.");
                    ˊ = 0;
                }
                o_adv.ॱ(ˊ);
                this.ˊᐝ = ॱ;
            }
            this.ˊˋ = this.ˊᐝ.ˋ.ᐝ[this.ˊᐝ.ˊ];
            if (this.ˊᐝ.ˊ < this.ˊᐝ.ॱॱ) {
                o_adv.ॱ(this.ˊˋ);
                this.ˊᐝ.ˊ();
                if (!this.ˊᐝ.ॱ()) {
                    this.ˊᐝ = null;
                }
                this.ॱˋ = 3;
                return true;
            }
            if (this.ˊᐝ.ˎ.ʻ == 1) {
                this.ˊˋ -= 8;
                o_adv.ॱ(8);
            }
            this.ˍ = this.ˊᐝ.ˏ();
            this.ˊˋ += this.ˍ;
            this.ॱˋ = 4;
            this.ˌ = 0;
        }
        afh o_afh = this.ˊᐝ.ˋ;
        Track track = this.ˊᐝ.ˎ;
        aef o_aef = this.ˊᐝ.ˏ;
        int i2 = this.ˊᐝ.ˊ;
        long ॱ2 = o_afh.ॱ(i2) * 1000;
        if (this.ˊॱ != null) {
            ॱ2 = this.ˊॱ.ˊ(ॱ2);
        }
        if (track.ʼ != 0) {
            byte[] bArr = this.ॱˊ.ˏ;
            bArr[0] = (byte) 0;
            bArr[1] = (byte) 0;
            bArr[2] = (byte) 0;
            int i3 = track.ʼ + 1;
            int i4 = 4 - track.ʼ;
            while (this.ˍ < this.ˊˋ) {
                if (this.ˌ == 0) {
                    o_adv.ˏ(bArr, i4, i3);
                    this.ॱˊ.ˋ(0);
                    this.ˌ = this.ॱˊ.ʽॱ() - 1;
                    this.ʽ.ˋ(0);
                    o_aef.ˎ(this.ʽ, 4);
                    o_aef.ˎ(this.ॱˊ, 1);
                    boolean z = this.ͺॱ.length > 0 && and.ˋ(track.ॱॱ.ʽ, bArr[4]);
                    this.ˋˋ = z;
                    this.ˍ += 5;
                    this.ˊˋ += i4;
                } else {
                    if (this.ˋˋ) {
                        this.ˋॱ.ˏ(this.ˌ);
                        o_adv.ˏ(this.ˋॱ.ˏ, 0, this.ˌ);
                        o_aef.ˎ(this.ˋॱ, this.ˌ);
                        i = this.ˌ;
                        int ˋ = and.ˋ(this.ˋॱ.ˏ, this.ˋॱ.ॱ());
                        this.ˋॱ.ˋ("video/hevc".equals(track.ॱॱ.ʽ) ? 1 : 0);
                        this.ˋॱ.ॱ(ˋ);
                        ajv.ॱ(ॱ2, this.ˋॱ, this.ͺॱ);
                        ˊ = i;
                    } else {
                        ˊ = o_aef.ˏ(o_adv, this.ˌ, false);
                    }
                    this.ˍ += ˊ;
                    this.ˌ -= ˊ;
                }
            }
        } else {
            while (this.ˍ < this.ˊˋ) {
                this.ˍ = o_aef.ˏ(o_adv, this.ˊˋ - this.ˍ, false) + this.ˍ;
            }
        }
        ˊ = o_afh.ॱˊ[i2] ? 1 : 0;
        o.aef.d dVar = null;
        afe ˎ = this.ˊᐝ.ˎ();
        if (ˎ != null) {
            i = 1073741824 | ˊ;
            dVar = ˎ.ˏ;
        } else {
            i = ˊ;
        }
        o_aef.ˋ(ॱ2, i, this.ˊˋ, 0, dVar);
        ˊ(ॱ2);
        if (!this.ˊᐝ.ॱ()) {
            this.ˊᐝ = null;
        }
        this.ॱˋ = 3;
        return true;
    }

    private void ˊ(long j) {
        while (!this.ॱˎ.isEmpty()) {
            b bVar = (b) this.ॱˎ.removeFirst();
            this.ʿ -= bVar.ˊ;
            long j2 = bVar.ˏ + j;
            if (this.ˊॱ != null) {
                j2 = this.ˊॱ.ˊ(j2);
            }
            for (aef ˋ : this.ˎˎ) {
                ˋ.ˋ(j2, 1, bVar.ˊ, this.ʿ, null);
            }
        }
    }

    private static d ॱ(SparseArray<d> sparseArray) {
        d dVar = null;
        long j = Long.MAX_VALUE;
        int size = sparseArray.size();
        int i = 0;
        while (i < size) {
            d dVar2;
            long j2;
            d dVar3 = (d) sparseArray.valueAt(i);
            long j3;
            if (dVar3.ʻ == dVar3.ˋ.ˋ) {
                j3 = j;
                dVar2 = dVar;
                j2 = j3;
            } else {
                long j4 = dVar3.ˋ.ʻ[dVar3.ʻ];
                if (j4 < j) {
                    dVar2 = dVar3;
                    j2 = j4;
                } else {
                    j3 = j;
                    dVar2 = dVar;
                    j2 = j3;
                }
            }
            i++;
            dVar = dVar2;
            j = j2;
        }
        return dVar;
    }

    private static DrmInitData ˋ(List<o.aeu.d> list) {
        int size = list.size();
        List list2 = null;
        for (int i = 0; i < size; i++) {
            o.aeu.d dVar = (o.aeu.d) list.get(i);
            if (dVar.ॱꓸ == aeu.ᐝᐝ) {
                if (list2 == null) {
                    list2 = new ArrayList();
                }
                byte[] bArr = dVar.ॱᐨ.ˏ;
                UUID ˎ = aff.ˎ(bArr);
                if (ˎ == null) {
                    amz.ˏ("FragmentedMp4Extractor", "Skipped pssh atom (failed to extract uuid)");
                } else {
                    list2.add(new SchemeData(ˎ, "video/mp4", bArr));
                }
            }
        }
        return list2 == null ? null : new DrmInitData(list2);
    }

    private static boolean ˋ(int i) {
        return i == aeu.ـ || i == aeu.ॱʻ || i == aeu.ˉ || i == aeu.ˊᐝ || i == aeu.ᐨ || i == aeu.ʾ || i == aeu.ʼॱ || i == aeu.ॱʼ || i == aeu.ˈ || i == aeu.ˋˊ || i == aeu.ᐝᐝ || i == aeu.ᶥ || i == aeu.ﾞ || i == aeu.ﹳ || i == aeu.ꞌ || i == aeu.ʹ || i == aeu.ﾟ || i == aeu.ॱͺ || i == aeu.ͺॱ || i == aeu.ٴ;
    }

    private static boolean ˊ(int i) {
        return i == aeu.ˊˊ || i == aeu.ˊˋ || i == aeu.ˋˋ || i == aeu.ˋᐝ || i == aeu.ˌ || i == aeu.ˎˏ || i == aeu.ˑ || i == aeu.ˏˎ || i == aeu.ॱʽ;
    }
}
